19. Jacobian Matrix Part 1
Jacobian Matrix Part 1
Jacobian Matrix
At 1:59 Andrei says, "you have to check that neither x nor y is zero." What is meant is: "you have to check that x and y are not both zero".
We're going to calculate, step by step, all the partial derivatives in H_j :
So all of H_j 's elements are calculated as follows:
In order to calculate the derivative of this function we use the quotient rule.
Given a function z that is quotient of two other functions, f and g :
its derivative with respect to x is defined as:
in our case:
Their derivatives are:
Putting everything together into the derivative quotient rule we have:
Similarly,
So now, after calculating all the partial derivatives, our resulted Jacobian, H_j is:
Jacobian Matrix Programming Quiz
Task Description:
FIll in the missing code in the
CalculateJacobian()
function to return the correct Jacobian matrix.
Task Feedback:
Great! Make sure you test your code below!
Start Quiz:
#include <iostream>
#include <vector>
#include "Dense"
using Eigen::MatrixXd;
using Eigen::VectorXd;
using std::cout;
using std::endl;
MatrixXd CalculateJacobian(const VectorXd& x_state);
int main() {
/**
* Compute the Jacobian Matrix
*/
// predicted state example
// px = 1, py = 2, vx = 0.2, vy = 0.4
VectorXd x_predicted(4);
x_predicted << 1, 2, 0.2, 0.4;
MatrixXd Hj = CalculateJacobian(x_predicted);
cout << "Hj:" << endl << Hj << endl;
return 0;
}
MatrixXd CalculateJacobian(const VectorXd& x_state) {
MatrixXd Hj(3,4);
// recover state parameters
float px = x_state(0);
float py = x_state(1);
float vx = x_state(2);
float vy = x_state(3);
// TODO: YOUR CODE HERE
// check division by zero
// compute the Jacobian matrix
return Hj;
}